home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 290 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  934 b 

  1. Path: castle.nando.net!news
  2. From: actuary@nando.net   (Bill McCarthy)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: qsort help
  5. Date: 4 Jan 1996 03:32:52 GMT
  6. Organization: News & Observer Public Access
  7. Message-ID: <4cfhp4$pd@castle.nando.net>
  8. References: <4ccio7$7c0@charm.magnus.acs.ohio-state.edu>
  9. Reply-To: actuary@nando.net (Bill McCarthy)
  10. NNTP-Posting-Host: grail2007.nando.net
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <4ccio7$7c0@charm.magnus.acs.ohio-state.edu>, xiaoyi@bmecg.bme.ohio-state.edu (Xiaoyi Wu) writes:
  14. >Hi, I am having some problems with the qsort routine.
  15. >
  16. >
  17. >int (*compar)(int *a, int *b)
  18. >{
  19. >  if (*a < *b) return -1;
  20. >  else if (*a == *b) return 0;
  21. >  else return 1;
  22. >}
  23.  
  24. The compare function for qsort takes two pointers to const void.
  25.  
  26. So,
  27.  
  28. int compar( const void *x, const void *y )
  29. {
  30.    const int *a = x;
  31.    const int *b = y;
  32.  
  33.    /* you function body goes here */
  34. }
  35.  
  36. Bill McCarthy
  37. actuary@nando.net
  38. Wendell, NC  USA
  39.  
  40.